//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XEditorWorkspace.h>
///	@path	~/src/editor/wm/
///	@date	2008/10/25
///	@desc	.

#pragma once

#pragma message("Compiling XEditorWorkspace.h ...")

#include "editor/editor.h"
#include "editor/wm/XFormView.h"
#include "editor/wm/XEngineView.h"

namespace xeres {

	/*! 
		\class	XEditorWorkspace
		\brief
	*/
	class XEditorWorkspace : public CWindowImpl< XEditorWorkspace >
	{
	public:
		DECLARE_WND_CLASS( _T("xeres__XEngineView") )

		/// \ctor
		XEditorWorkspace( void ) {
		}
		/// \dtor
		~XEditorWorkspace( void ) {
		}

		BOOL PreTranslateMessage(MSG* pMsg)
		{
			UNREFERENCED_PARAMETER( pMsg );
			return FALSE;
		}

		BEGIN_MSG_MAP(XEditorWorkspace)
			MESSAGE_HANDLER(WM_ACTIVATE , OnActivate)
			MESSAGE_HANDLER(WM_CREATE, OnCreate)
			MESSAGE_HANDLER(WM_PAINT , OnPaint)
			MESSAGE_HANDLER(WM_SIZE , OnSize)
			MESSAGE_HANDLER(WM_ERASEBKGND , OnEraseBkgnd)
		END_MSG_MAP()

		LRESULT OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
			// Dummy filter to refresh dispatcher states.
			return S_OK;
		}
		LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
			// Setup ticking timer (30fps).
			this->SetTimer( TIMER_TICK , static_cast<int>( 1000.f / 30.f ) );
			m_engineView.Create( m_hWnd, rcDefault, NULL, WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN );
			return S_OK;
		}
		LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
			CPaintDC dc( m_hWnd );
			return S_OK;
		}
		LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled ) {
			// resize engine
			CRect rect;
			GetClientRect( &rect );
			m_engineView.SetWindowPos( NULL , &rect , SWP_SHOWWINDOW );
			return S_OK;
		}
		LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
			return S_OK;
		}

		/// \brief	Get engine view.
		XEngineView& GetEngineView( void )
		{
			return m_engineView;
		}

	private:

		//@ data
		XEngineView		m_engineView;
	};

	
} // namespace xeres
